﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace demo
{
[System.Serializable]
public class PathNavigator 
{
    private System.Collections.Generic.Stack<string> Prevs
        = new Stack<string>();

    private System.Collections.Generic.Stack<string> Nexts
        = new Stack<string>();

    private string currentPath;

    public string Path
    {
        get { return this.currentPath; }
    }

    public PathNavigator()
    {
    }

    public PathNavigator(string current)
    {
        this.currentPath = current;
    }

    public void Enter(string path)
    {
        if (this.currentPath == null)
        {
            this.currentPath = path;
            return;
        }

        this.Prevs.Push(this.currentPath);
        this.currentPath = path;
        this.Nexts.Clear();
    }

    public string Next()
    {
        if (this.Nexts.Count == 0)
        {
            throw new InvalidOperationException("后继中没有内容！");
        }
        this.Prevs.Push(this.currentPath);
        this.currentPath = this.Nexts.Pop();
        return this.currentPath;
    }

    public string Prev()
    {
        if (this.Prevs.Count == 0)
        {
            throw new InvalidOperationException("前面内容内容！");
        }

        this.Nexts.Push(this.currentPath);
        this.currentPath = this.Prevs.Pop();
        return this.currentPath;
    }


       
}
}
